#pragma once
#ifndef _CLIENT_MANAGER_H_
#define _CLIENT_MANAGER_H_

class CClientBase
{
friend class CClientManager;
protected:
	CClientBase();
	virtual	~CClientBase();

	xgc_void AllocIdentify();
	xgc_void DellocIdentify();

private:
	xgc_void Fetch(){ mLock.lock(); }
	xgc_void Free(){ mLock.free(); }

public:
	xgc_uint16	GetObjectID()const{ return OID; }
protected:
	xgc_uint16	OID;
	section		mLock;
};

class CClientManager
{
friend struct CreateUsingNew< CClientManager >;
friend class CClientBase;
private:
	CClientManager();
	~CClientManager(void);

public:
	 xgc_bool Initialize( xgc_uint16 nPoolSize );

	 CClientBase* FetchClient( xgc_uint16 OID );
	 xgc_void FreeClient( CClientBase* pClient );
private:
	xgc_void AppendObject( CClientBase *pObj );
	xgc_void RemoveObject( CClientBase *pObj );

	CClientBase **pObjectPool;
	xgc_uint16 mCurrentOID;
	xgc_uint16 mCurrentFree;

	xgc_uint16 mPoolSize;
	section mGuard;
};

typedef SingletonHolder< CClientManager, CreateUsingNew > ClientManager;
#endif // _CLIENT_MANAGER_H_